﻿using System;
using System.Collections.Generic;
using System.Text;

// Copyright Pohlod Yaroslav 

namespace Assembler_Compiler
{
    public enum ErrorType
    {
        Compile,
        Build,
        Run
    };

    // Class for representation info about single error
    public struct Error
    {
        public String Message { get; set; }
        public int Line { get; set; }
        public ErrorType Type { get; set; }
    }

    // Class for storing compilation errors
    public static class ErrorList
    {
        // list with errors
        private static List<Error> errors = new List<Error>();

        // count of errors
        public static int Count
        {
            get
            {
                return errors.Count;
            }
        }

        // get error at specified index
        public static Error GetError(int index)
        {
            if (index < 0 || index >= errors.Count)
                throw new ArgumentOutOfRangeException("Index of error is out of range.");
            return errors[index];
        }

        // add new error
        public static void AddError(Error msg)
        {
            msg.Message = msg.Message.Split(';')[0];
            errors.Add(msg);
        }

        // clean all errors
        public static void Clean()
        {
            errors.Clear();
            errors = new List<Error>();
        }

    }
}
